<?php

class Packet extends CActiveRecord
{
	/**
	 * The followings are the available columns in table 'yii_packets':
	 * @var integer $id
	 * @var string $name
	 * @var string $payment_sum
	 * @var integer $unlim
	 * @var integer $default_speed_id
	 * @var string $world_cost
	 * @var string $ukraine_cost
	 * @var string $world_night_cost
	 * @var string $ukraine_night_costId
	 * @var integer $active
	 * @var string $change_time
	 */

	/**
	 * Returns the static model of the specified AR class.
	 * @return CActiveRecord the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{packets}}';
	}
	
	public function scopes()
	{
		return array(
			'active'=>array(
				'condition'=>'t.active=1',
				'order'=>'t.id',
			),
			//'withspeed'=>array(
				//'with'=>'speed',
			//),
		);
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('name, payment_sum, change_time', 'required'),
			array('unlim, default_speed_id, active', 'numerical', 'integerOnly'=>true),
			array('name', 'length', 'max'=>60),
			array('payment_sum, world_cost, ukraine_cost, world_night_cost, ukraine_night_cost', 'length', 'max'=>10),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'speed'=>array(self::BELONGS_TO,'Speed','default_speed_id',
						'select'=>'id,name',),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => Yii::t('packet', 'Id'),
			'name' => Yii::t('packet', 'Name'),
			'payment_sum' => Yii::t('packet', 'Payment Sum'),
			//'traffic_sum' => Yii::t('packet', 'Traffic Sum'),
			'unlim' => Yii::t('packet', 'Unlim'),
			'default_speed_id' => Yii::t('packet', 'Default Speed'),
			'world_cost' => Yii::t('packet', 'World Cost'),
			'ukraine_cost' => Yii::t('packet', 'Ukraine Cost'),
			'world_night_cost' => Yii::t('packet', 'World Night Cost'),
			'ukraine_night_cost' => Yii::t('packet', 'Ukraine Night Cost'),
			'active' => Yii::t('packet', 'Active'),
			'change_time' => Yii::t('packet', 'Change Time'),
		);
	}
}